#include <iostream>
using namespace std;

const int N = 1e5+10;

int e[N],ne[N],h,id;
int mp[N];

void push_front(int x){
	id++;
	e[id] = x;
	mp[x] = id;
	ne[id] = ne[h];
	ne[h] = id;
}

void print(){
	for(int i = ne[h];i;i = ne[i]){
		cout << e[i] << " ";
	}
	cout << endl << endl;
} 

int find(int x){
//	for(int i = ne[h];i;i = ne[i]){
//		if(e[i] == x){
//			return i;
//		}
//	}
//	return -1;
	return mp[x];
}

void insert(int p,int x){
	id++;
	e[id] = x;
	mp[x] = id;
	ne[id] = ne[p];
	ne[p] = id;
} 

void erase(int p){
	if(ne[p]){
		mp[e[ne[p]]] = 0;
		ne[p] = ne[ne[p]];
	}
}

int main(){
	for(int i = 1;i <= 5;i++){
		push_front(i); 
	}
	print();
	
	cout << find(2) << endl;
	cout << find(3) << endl;
	cout << find(6) << endl;
	
//	insert(1,10);
//	print();
//	insert(2,100);
//	print();

	erase(2);
	print();
	erase(4);
	print(); 
	return 0;
}
